import java.util.*;

/**
 * @author LKQ
 * @date 2022/4/2 21:27
 * @description 假设为行降序，列降序，那么从右上角或左下角开始都行
 */
public class Solution {
    public static void main(String[] args) {
        Solution solution = new Solution();
        int[][] matrix = {{30, 26, 23, 21, 18}, {24, 17, 14, 13, 10}, {22, 16, 9, 6, 3}, {19, 12, 8, 5, 2}, {15, 11, 7, 4, 1}};
        solution.searchMatrix(matrix, 12);
    }

    public boolean searchMatrix(int[][] matrix, int target) {
        int m = matrix.length, n = matrix[0].length;
        int x = 0, y = n - 1;
        while (x < m && y >= 0) {
            int t = matrix[x][y];
            if (t == target) {
                return true;
            } else if (t > target) {
                x++;
            } else {
                y--;
            }
        }

        return false;
    }
}
